package cn.tedu.hospitalgroupproject.server.content.controller;

import cn.tedu.hospitalgroupproject.server.common.pojo.vo.PageData;
import cn.tedu.hospitalgroupproject.server.common.web.JsonResult;
import cn.tedu.hospitalgroupproject.server.content.pojo.vo.DoctorListItemVO;
import cn.tedu.hospitalgroupproject.server.content.pojo.vo.PatientListVO;
import cn.tedu.hospitalgroupproject.server.content.pojo.vo.PatientStandardVO;
import cn.tedu.hospitalgroupproject.server.content.service.IPatientService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/management/patients/")
@Api(tags="1.8 管理部分-患者管理")
public class PatientController {

    @Autowired
    private IPatientService patientService;

    @ApiOperation("查询患者列表")
    @ApiOperationSupport(order = 420)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", dataType = "int"),
            @ApiImplicitParam(name = "queryType", value = "查询类型，当需要查询全部数据时，此参数值应该是all")
    })
    @GetMapping("/list")
    public JsonResult listPatient(Integer page, String queryType) {
        log.debug("开始处理【查询患者列表】请求，页码：{}", page);
        if (page == null) {
            page = 1;
        }
        Integer pageNum = page > 0 ? page : 1;
        PageData<PatientListVO> pageData ;
        if ("all".equals(queryType)) {
            pageData = patientService.list(1, Integer.MAX_VALUE);
        } else {
            pageData = patientService.list(pageNum);
        }
        return JsonResult.ok(pageData);
    }

    @ApiOperation("根据id查询患者信息")
    @ApiOperationSupport(order = 430)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "患者id", dataType = "long"),
    })
    @GetMapping("/getStandard")
    public JsonResult listPatient(Long id) {
        log.debug("开始处理【查询患者信息】请求，参数id：{}", id);
        PatientStandardVO patientStandardVO = patientService.getStandardById(id);
        return JsonResult.ok(patientStandardVO);
    }

}
